package com.liugui.springbootexceptionhandler.vo;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.liugui.springbootexceptionhandler.enums.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

/**
 * @author liugui
 * @description 自定义统一响应体
 */
@Data
@ApiModel
public class ResultVO<T> {

    @ApiModelProperty(value = "状态码", notes = "默认1000是成功")
    private  Integer code;
    @ApiModelProperty(value = "响应信息", notes = "来说明响应情况")
    private  String  msg;
    @ApiModelProperty(value = "响应的具体数据")
    private  T       data;

    public ResultVO() { }

    public ResultVO(T data) {
        this(ResultCode.SUCCESS, data);
    }

    public ResultVO(Integer code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResultVO(ResultVO<T> resultVO,Integer code){
        this.code = code;
        this.msg = resultVO.getMsg();
        this.data = resultVO.getData();
    }

    public ResultVO(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultVO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
